﻿@model XSTDZ.ERP.Application.DataContracts.ReturnBillDto

@{
    ViewBag.Title = " - 编辑退货单";
}
@section header{
     <link href="@Url.Content("~/Content/Controls.css")" rel="stylesheet" type="text/css" />
 <link href="@Url.Content("~/Content/Form.css")" rel="stylesheet" type="text/css" />
}
<div class="wp100">

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <table class="formtable">
    <thead>
        <tr>
            <th colspan="4">@* <h2>新增入库单</h2>*@
            <div id="toptoolbar"></div>
            </th>
        </tr>
    </thead>
     <tr>
        <td class="title"> @Html.LabelFor(model => model.ReturnBillNo)</td>
        <td> @Html.TextBoxFor(model => model.ReturnBillNo, new { @class = "text disablebg", @readonly = "readonly" })
        @Html.ValidationMessageFor(model => model.ReturnBillNo)
         <input type="hidden" value="@ViewBag.TempId" id="hidbillDetailId" name="hidbillDetailId" />
          @Html.HiddenFor(model => model.Id)
           @Html.HiddenFor(model => model.BillState)
           @Html.HiddenFor(model => model.AffirmState)
        </td>

        <td class="title">@Html.LabelFor(model => model.StorehouseID)<b>*</b></td>
        <td>  @Html.TextBoxFor(model => model.StorehouseName, new { @class = "text" })
          @Html.HiddenFor(model => model.StorehouseID)
            @Html.ValidationMessageFor(model => model.StorehouseID)
         </td>
  </tr>
    
         <tr>
       
        <td class="title"> @Html.LabelFor(model => model.ReturnBillorID)<b>*</b></td>
        <td> @Html.TextBoxFor(model => model.ReturnBillorName, new { @class = "text" })
         @Html.HiddenFor(model => model.ReturnBillorID)
        @Html.ValidationMessageFor(model => model.ReturnBillorID)
        </td>

         <td class="title"> @Html.LabelFor(model => model.ReturnTime)<b>*</b></td>
        <td> @Html.TextBoxFor(model => model.ReturnTime, new { @class = "text" })
         <input type="hidden" value="@Model.ReturnTime" id="ReturnTimeVal" name="ReturnTimeVal" />
        @Html.ValidationMessageFor(model => model.ReturnTime)
        </td>
  </tr> 
      
               <tr>
       
        <td class="title"> @Html.LabelFor(model => model.SenderID)<b>*</b></td>
        <td> @Html.TextBoxFor(model => model.SenderName, new { @class = "text" })
         @Html.HiddenFor(model => model.SenderID)
        @Html.ValidationMessageFor(model => model.SenderID)
        </td>

         <td class="title"> @Html.LabelFor(model => model.DeliveryID)<b>*</b></td>
        <td> @Html.TextBoxFor(model => model.DeliveryName, new { @class = "text" })@if (@ViewBag.orgCode != XSTDZ.ERP.Infrastructure.SystemConfig.ShengZhenCode)
                                                                                   {<a href="javascript:void(0);" onclick="javascript:selectOrg();" >选择</a>}
         @Html.HiddenFor(model => model.DeliveryID)
        @Html.ValidationMessageFor(model => model.DeliveryID)
        </td>
  </tr> 
         <tr>
        <td class="title"> @Html.LabelFor(model => model.Remarks)</td>
        <td> @Html.TextBoxFor(model => model.Remarks, new { @class = "text" })
        @Html.ValidationMessageFor(model => model.Remarks)
        </td>

        <td class="title"></td>
        <td>  
         </td>
  </tr> 
   @if (Model.BillState != 1)
   {
 <tr>
        <td  colspan="4">
              <p class="divBtn">
                <input type="hidden" value="" name="hidProductBillItems" id="hidProductBillItems" />
               <input type="hidden" id="hidHttpRefeParent" name="hidHttpRefeParent" value="grid" />
            <input type="button" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnSave"  class="BtnSubmit" id="submitBtn" name="submitBtn" />
            <input type="button" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnSubmit"  class="BtnSubmit" id="btnSubmit" name="btnSubmit" />
        </p>
        </td>
    </tr>
   }
    </table>
}
</div>
<div class="wp100">
<div id="ReturnBillItemsGrid" style="margin-top:20px" ></div>
</div>
<input id="HidOrgCode" name="HidOrgCode" type="hidden" value="@ViewBag.orgCode" />
        <input id="HidEmptyGuid" name="HidEmptyGuid" type="hidden" value="@Guid.Empty" />

<script type="text/javascript">
    $(document).ready(function () {
        //确认时间
        $("#ReturnTime").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
        $("#ReturnTime").ligerGetDateEditorManager().setValue($("#ReturnTimeVal").val());
//        //确认时间
//        $("#AffirmDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
//        $("#AffirmDate").ligerGetDateEditorManager().setValue($("#AffirmDateVal").val());
        //库房
        $("#StorehouseName").ligerPopupEdit({
            grid: getGridOptions(false),
            valueField: 'Id',
            textField: 'StorehouseName'
        });

        //退货人
        getSelectUserGrid("ReturnBillorName");
//        $("#ReturnBillorName").ligerPopupEdit({
//            grid: getUserGridOptions(false),
//            valueField: 'Key',
//            textField: 'Name'
//        });
        //送货人
        getSelectUserGrid("SenderName");
//        $("#SenderName").ligerPopupEdit({
//            grid: getUserGridOptions(false),
//            valueField: 'Key',
//            textField: 'Name'
//        });

        $("#submitBtn").unbind("click").bind("click", function () { getProductBillItemData(false); }); //保存
        $("#btnSubmit").unbind("click").bind("click", function () { getProductBillItemData(true); }); //提交
    });

    function getProductBillItemData(isConfirm) {
        if ($("#BillState").val() == "1") { $.ligerDialog.success("已提交，不能再更新!"); }
        else {
            if (manager != null && manager != undefined) {
                if (!validateGridDetail(manager, "ReturnNo")) { $.ligerDialog.success('明细数量不能小于0!'); return; }; //验证明细
                var data = manager.getData();
                $("#hidProductBillItems").val("").val(JSON.stringify(data));
                if (!isConfirm) {
                    btnText = $("#submitBtn").val();
                    $("#submitBtn").val("").val("正在处理中...");
                }
                else {
                    btnText = $("#btnSubmit").val();
                    $("#btnSubmit").val("").val("正在处理中...");
                }
                $.ajax({ type: "POST", url: "/ReturnBill/AddAndConfirm?isConfirm=" + isConfirm, data: $("form").serialize(), // 要提交的表单
                    success: function (msg) {
                        if (msg == "9") {
                            ajaxSubmitSuccess();
                            $.ligerDialog.success('操作成功!');
                            initligerGrid();
                        }
                        else if (msg == "0") {
                            $.ligerDialog.success('数据不完整,请输入必填数据后再提交!');
                        }
                        else if (msg == "-1") {
                            $.ligerDialog.success('入库单明细数据不完整,操作失败!');
                        }
                        else if (msg == "-3") {
                            $.ligerDialog.success('退货单明细退货数量超过库存数量,操作失败!');
                        }
                        else {
                            $.ligerDialog.success('操作失败!');
                        }
                        if (!isConfirm) { $("#submitBtn").val("").val(btnText); } else { $("#btnSubmit").val("").val(btnText); }
                    }
                });
            }
        }
    }

    //收货单位
    function selectOrg() {
        var returnValue = window.showModalDialog('../Org/SelectOrgTree?selectType=1', window, "help:No;resizable:No;status:No;scroll:yes;dialogWidth=300px;dialogHeight=300px");
        $("#DeliveryName").val(returnValue[0]);
        $("#DeliveryID").val(returnValue[1]);
    }
</script>


<script type="text/javascript" src="@Url.Content("~/Scripts/ligerUI/js/plugins/ligerPopupEdit.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/ligerUI/js/plugins/ligerDateEditor.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/ReturnBill/Add.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/SelectData.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/formBase.js")"></script>